<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<title>Critical Section Operation</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="generator" content="Doc-O-Matic" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <link rel="STYLESHEET" href="default.css" type="text/css" />

<script type="text/javascript" src="scripts.js"></script>
</head>
<body class="Element700" onload="onBodyLoadEx('frames.html', 'topic', '00631.html');" onmousedown="onBodyMouseDown();">

<!-- Begin Popups -->

<!-- End Popups -->

<!-- Begin Page Header -->
<div class="Element710" id="areafixed">
<div class="Element94">
<a href="00626.html" target="topic">OSAL Library Help</a> &gt; <a href="00645.html" target="topic">Using the Library</a> &gt; <a href="00633.html" target="topic">How the Library Works</a> &gt; <a href="00631.html" target="topic">Critical Section Operation</a></div>
<div class="Element92">
<table width="100%" cellspacing="0" cellpadding="0">
<tr><td width="25%">
<div class="Element1">
MPLAB Harmony Core Help</div>
</td><td width="25%">
<div class="Element2">
<a href="contents.html" target="tocidx">Contents</a> | <a href="00007.html" target="topic">Home</a></div>
</td><td width="25%">
<div class="Element90">
<a href="00640.html" target="topic">Previous</a> | <a href="00633.html" target="topic">Up</a> | <a href="00638.html" target="topic">Next</a></div>
</td><td width="25%">
<div class="Element96">
<a href="mailto:docerrors@microchip.com&subject=MPLAB Harmony Documentation Feedback (Topic ID: OSAL Critical Section Operation Topic Title: Critical Section Operation)&body=Thank you for your feedback! Please include a description of your feedback, and indicate whether you are reporting an an error in the documentation or an enhancement.">Documentation Feedback</a><br> <a href="http://support.microchip.com" target="_blank">Microchip Support</a></div>
</td></tr></table><div class="Element5">
Critical Section Operation</div>
</div>
</div>

<!-- End Page Header -->

<!-- Begin Client Area -->
<div class="Element720" id="areascroll">
<div class="Element721">

<!-- Begin Page Content -->
<a name="PageContent"></a><div class="Element58">
<a name="4465736372697074696F6E"></a><div class="Element11">
<div class="Element10">
<p class="Element10" style="text-align: justify;">
Critical sections are used to form sequences of code that must operate in an atomic manner. The interface allows for the possibility of two types of critical section.</p>
<ul class="Element630">
<li class="Element600">When the critical section is entered all interrupts on the microcontroller are disabled. This prevents the protected sequence of code from being interrupted and ensures the complete atomicity of the operation. This is denoted by the OSAL_CRIT_TYPE_HIGH value</li>
<li class="Element600">When the critical section is entered the RTOS scheduler is disabled. In this second case other threads are prevented from running however interrupts can still occur which allows any asynchronous events to still be received and for the temporal accuracy of the RTOS scheduler to be maintained. This is denoted by the OSAL_CRIT_TYPE_LOW value</li>
</ul><p class="Element10">
Since the behavior in the two cases is different the type of critical section must be identified in both the call to enter and leave. </p><div class="Element13"><div class="Element12"><pre class="Element12"><i><span style="color: #008000">/* enter and leave a critical section disabling interrupts */</span></i>
OSAL_CRIT_Enter(OSAL_CRIT_TYPE_HIGH);
<i><span style="color: #008000">/* perform an atomic sequence of code */</span></i>
...
<i><span style="color: #008000">/* leave the critical section */</span></i>
OSAL_CRIT_Leave(OSAL_CRIT_TYPE_HIGH);</pre></div></div>
<p class="Element10">
The underlying RTOS may not support the second scenario, in which case the OSAL implementation will default to disabling all interrupts.</p></div>
</div>
</div>
<!-- End Page Content -->

<!-- Begin Page Footer -->
<div class="Element95">
<a href="00626.html" target="topic">OSAL Library Help</a> &gt; <a href="00645.html" target="topic">Using the Library</a> &gt; <a href="00633.html" target="topic">How the Library Works</a> &gt; <a href="00631.html" target="topic">Critical Section Operation</a></div>
<div class="Element93">
<table width="100%" cellspacing="0" cellpadding="0">
<tr><td width="25%">
<div class="Element3">
MPLAB Harmony Core Help</div>
</td><td width="25%">
<div class="Element4">
<a href="contents.html" target="tocidx">Contents</a> | <a href="00007.html" target="topic">Home</a></div>
</td><td width="25%">
<div class="Element91">
<a href="00640.html" target="topic">Previous</a> | <a href="00633.html" target="topic">Up</a> | <a href="00638.html" target="topic">Next</a></div>
</td><td width="25%">
<div class="Element97">
<a href="mailto:docerrors@microchip.com&subject=MPLAB Harmony Documentation Feedback (Topic ID: OSAL Critical Section Operation Topic Title: Critical Section Operation)&body=Thank you for your feedback! Please include a description of your feedback, and indicate whether you are reporting an an error in the documentation or an enhancement.">Documentation Feedback</a><br> <a href="http://support.microchip.com" target="_blank">Microchip Support</a></div>
</td></tr></table></div>

<!-- End Page Footer -->
</div>
</div>

<!-- End Client Area -->
</body></html>